import jsBridge from './jsBridge';
import store from '@/store'
export default {
	//关闭webview
	closeWebPage: function () {
		return jsBridge.doCall('closeWebPage')
	},
	//去首页
	goHome: function () {
		let actName = '';
		//ios
		if (!store.state.deviceType) {
			actName = 'XCHomeVC';
		}else{
			actName = 'com.alkj.secondhand.ui.MainActivity_0';
		}
		return new Promise(function (resolve, reject) {
			jsBridge.doCall('openAct', 
			  {
				"actName": actName,
			  },(res)=>{
				if (window.location.hostname != 'h5.xianchaoshop.com') {
					console.log(res)
				}
				resolve(res);
			})
		});
	},
	//去登陆
	goLogin: function () {
		let actName = '';
		//ios
		if (!store.state.deviceType) {
			actName = 'XCLoginVC';
		}else{
			actName = 'com.alkj.secondhand.ui.login.LoginActivity';
		}
		return new Promise(function (resolve, reject) {
			jsBridge.doCall('openAct', 
			  {
				"actName": actName,
			  },(res)=>{
				if (window.location.hostname != 'h5.xianchaoshop.com') {
					console.log(res)
				}
				resolve(res);
			})
		});
	},
	//去商品详情页
	goGoodsDetail: function (id) {
		//ios
		if (!store.state.deviceType) {
			return new Promise(function (resolve, reject) {
				jsBridge.doCall('openAct', 
				  {
					"actName": "XCGoodsDetailVC",
					"params":{
						"goodsId":id+''
					}
				  },(res)=>{
					if (window.location.hostname != 'h5.xianchaoshop.com') {
						console.log(res)
					}
					resolve(res);
				})
			});
		}else{
			return new Promise(function (resolve, reject) {
				jsBridge.doCall('openAct', 
				  {
					"actName": "com.alkj.secondhand.ui.goods.GoodsDetailActivity",
					"params":{
						"key_goods_id":id+''
					}
				  },(res)=>{
					if (window.location.hostname != 'h5.xianchaoshop.com') {
						console.log(res)
					}
					resolve(res);
				})
			});
		}
	},
	//复制
	copy: function (vaule) {
		return jsBridge.doCall('jsCopy',{value:vaule?vaule:''});
	},
	//去支付
	goPay: function (orderId,type) {
		return new Promise(function (resolve, reject) {
			jsBridge.doCall('goPay',{orderId:orderId?orderId:'',type:type?type:''},(res)=>{
				if (window.location.hostname != 'h5.xianchaoshop.com') {
					console.log(res)
				}
				resolve(res);
			});
		});
	},
	//选择地址
	onSelectAddress: function (data) {
		return new Promise(function (resolve, reject) {
			jsBridge.doCall('onSelectAddress',data,(res)=>{
				if (window.location.hostname != 'h5.xianchaoshop.com') {
					console.log(res)
				}
				resolve(res);
			});
		});
	},
	//去聊天
	goChat: function (mobile) {
		return new Promise(function (resolve, reject) {
			jsBridge.doCall('goChat',{mobile:mobile?mobile:''},(res)=>{
				if (window.location.hostname != 'h5.xianchaoshop.com') {
					console.log(res)
				}
				resolve(res);
			});
		});
	},
}
